package com.bingbing.back.service.Impl;

import com.bingbing.back.dto.SchoolMajorDto;
import com.bingbing.back.mapper.SchoolMajorMapper;
import com.bingbing.back.po.SchoolMajor;
import com.bingbing.back.service.SchoolMajorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SchoolMajorServiceImpl implements SchoolMajorService {
    @Resource
    private SchoolMajorMapper schoolMajorMapper;

    @Override
    public List<SchoolMajor> showSchoolNationMajor(int schoolId) {
        return schoolMajorMapper.showSchoolNationMajor(schoolId);
    }

    @Override
    public List<SchoolMajorDto> showSchoolAllMajor(int schoolId) {
        List<SchoolMajorDto> result = new ArrayList<>();
        List<SchoolMajor> Class = schoolMajorMapper.showSchoolMajorClass(schoolId);
        Class.forEach(s->{
            s.setSchoolId(schoolId);
            List<SchoolMajor> list = schoolMajorMapper.showSchoolMajorByClass(s);

            SchoolMajorDto dto = new SchoolMajorDto();
            dto.setMajorClass(s.getMajorClass());
            dto.setSchoolMajors(list);

            result.add(dto);
        });
        return result;
    }
}
